// 确保文件加载完成之后再渲染
import {Resources} from "./Resources.js";

export class ResourceLoader{
    constructor() {
        this.map=new Map(Resources);
        for(let [key,value] of this.map){
            const image=new Image();
            image.src=value;
            this.map.set(key,image);
        }
    }
    onLoaded(callback){
        let loadedCount=0;
        for(let value of this.map.values()){
            value.onload=()=>{
                loadedCount+=1;
                if(loadedCount>=this.map.size){
                    callback(this.map);
                }
            }
        }
    }

    static create(){
        return new ResourceLoader();
    }
}
